package com.fht.service.statement.impl;

import com.fht.entity.StatementOrderParticulars;
import com.fht.mapper.statement.StatementOrderParticularsMapper;
import com.fht.service.statement.StatementOrderParticularsService;
import com.fht.util.UnitConversionUtil;
import com.fht.vo.LayUITableVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class StatementOrderParticularsServiceImpl implements StatementOrderParticularsService {

    @Resource
    public StatementOrderParticularsMapper statementOrderParticularsMapper;

    @Override
    public LayUITableVO<List<StatementOrderParticulars>> findPage(Map<String, Object> map) {

        PageHelper.startPage((int) map.get("page"),(int) map.get("limit"));


        List<StatementOrderParticulars> list = statementOrderParticularsMapper.findPage(map);

        PageInfo<StatementOrderParticulars> pageInfo = new PageInfo<>(list);
        for (StatementOrderParticulars statementOrderParticulars : list) {
            statementOrderParticulars.setCreated(UnitConversionUtil.conversionDate(statementOrderParticulars.getCreated()));
            statementOrderParticulars.setTotal(String.valueOf(statementOrderParticulars.getNum()*statementOrderParticulars.getPrice()/100.0));
        }

        LayUITableVO<List<StatementOrderParticulars>> vo = new LayUITableVO<>();
        vo.setCount(pageInfo.getTotal());
        vo.setData(pageInfo.getList());

        return vo;
    }
}
